
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer,BadSignature
from mall import settings
def generic_verify_url(user_id,email):


    # url中含有用户信息
    #1.创建序列化器
    serializer = Serializer(settings.SECRET_KEY,3600)
    #2.组织数据
    data = {
        'id':user_id,
        'email':email
    }

    #3.加密
    token = serializer.dumps(data)

    return 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token.decode()

def check_active_token(token):
    #1.创建序列化器
    serializer = Serializer(settings.SECRET_KEY,3600)

    #2.通过loads方法解密
    try:
        result = serializer.loads(token)
    except BadSignature:
        return None
    else:
        return result.get('id')







